<template>
  <div>
    <h1>父组件</h1>
    <hr />
    <Son :money="money" @change-money="changeMoney"/>
  </div>
</template>

<script>
import { ref,provide } from 'vue'
import Son from '@/views/组件通信/son.vue'
export default {
  components: {
    Son,
  },
  setup() {
    // 父子通信
    const money = ref(1e6)
    const changeMoney = (mky) => {
      money.value = mky
    }

    // 跨多级组件通信
    // 语法 provide('注入数据名称',共享data)
    provide('mky',money)
    provide('changeMoney', changeMoney)
    return { money,changeMoney }
  },
}
</script>

<style></style>
